package com.hznu.jspFinal.controller;


import com.hznu.jspFinal.entity.CourseStudent;
import com.hznu.jspFinal.myBeans.R;
import com.hznu.jspFinal.service.CourseStudentService;
import com.hznu.jspFinal.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * author : wp
 * time : 10:06 2018/06/07
 */

@Api(description = "教学班学生管理接口",value = "courseStudent")
@RestController
@RequestMapping("/CourseStudent")
public class CourseStudentController {

    @Autowired
    private CourseStudentService courseStudentService;


    @ApiOperation(value = "教学班添加学生")
    @PostMapping("/add")
    public R addOne(@RequestBody CourseStudent courseStudent)
    {
        try{
            courseStudentService.addOne(courseStudent);
            return R.ok();
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }

    @ApiOperation(value="通过id删除教学班中的学生")
    @GetMapping("/deleteById/{id}")
    public R deleteById(@PathVariable Integer id)
    {
        try{
            courseStudentService.delete(id);
            return R.ok();
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }

    @ApiOperation(value="通过授课表id查找该教学班的所有学生信息")
    @GetMapping("/findStudentsByCourseTeacherid/{id}")
    public R findStudentsByCourseTeacherid(@PathVariable Integer id)
    {
        try{
            return R.ok().put("data",courseStudentService.findStudentsByCourseTeacherid(id));
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }

    /**
     * time : 16:56 2018/06/13
     * @param id
     * @return
     */
    @ApiOperation(value = "通过学生id(userid)查找该学生的所有教学班")
    @GetMapping("/findCoursesByStudentid/{id}")
    public R findCoursesByStudentid(@PathVariable Integer id)
    {
        try{
            return R.ok().put("data",courseStudentService.findCoursesByStudentid(id));
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }
}
